package database;

import java.sql.ResultSet;
import java.sql.SQLException;


public class DatabaseOperationsIdentifiers {
	
    
	private ConnectionDB conn;
		
	
	public DatabaseOperationsIdentifiers(ConnectionDB conn){
		this.conn = conn;
	}
	
	
    public  void insertIdentifier(String email,int id)
            throws SQLException{
		conn.executeUpdate("call createIdentifier('"+email+"',"+id+")");
	}


    public boolean existsIdentifier(String email)
            throws SQLException{

		boolean exists = false;

		ResultSet result = conn.executeSelect("call existsIdentifier('"+email+"')");

		if(result.next())
			exists = true;

		result.close();
		conn.closeStatement();

		return exists;
	}


    public boolean existsIdentifierId(String email, int id)
            throws SQLException{

		boolean exists = false;

		ResultSet result = conn.executeSelect("call existsIdentifierId('"+email+"',"+id+")");

		if(result.next())
			exists = true;

		result.close();
		conn.closeStatement();

		return exists;
	}


    public  void setIdentifierId(String email,int id)
            throws SQLException{
		conn.executeUpdate("call setIdentifierId('"+email+"',"+id+")");
	}


    public void setNumberCapsulesIdentifier(String email, int id, int numberCapsules)
            throws SQLException {
        conn.executeUpdate("call updateNumberCapsulesIdentifier('"+email+"',"+id+","+numberCapsules+")");
    }


     public void setOfferedSpaceIdentifier(String email, int id, long offeredSpace)
            throws SQLException {
        conn.executeUpdate("call updateOfferedSpaceIdentifier('"+email+"',"+id+","+offeredSpace+")");
    }


    public void setUsedSpaceIdentifier(String email, int id, long usedSpace)
            throws SQLException {
          conn.executeUpdate("call updateUsedSpaceIdentifier('"+email+"',"+id+","+usedSpace+")");
    }


 	public void close()
            throws SQLException{
		if(conn!=null){
			conn.close();
    	}
	}



	
}